Announcement

Collapse
No announcement yet.

Relative Volatility Index – Revised Computation Basis

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Relative Volatility Index – Revised Computation Basis

    I found this code for the RVI [by Donald Dorsey] provided by TS Support on February 28, 2003:

    code:


    / **************************************************
    Description: This Indicator plots the Relative Volitility Index

    Provided By: TS Support, LLC for eSignal

    ************************************************** */



    function preMain(){

    setStudyTitle("Relative Volatility Index");

    setCursorLabelName("RVI",0);

    setDefaultBarFgColor(Color.red,0);

    addBand(30, PS_SOLID, 1, Color.grey);

    addBand(70, PS_SOLID, 1, Color.grey);

    }

    var U_1 = 0;

    var D_1 = 0;

    var ma = null;





    function main(Period){

    if(Period == null)

    Period = 10;

    var StdDev = 0, u = 0, d = 0, U = 0, D = 0, SumSqr = 0;

    if(ma == null)

    ma = new MAStudy(Period, 0, "Close", MAStudy.SIMPLE);



    for(counter = - Period + 1; counter <= 0; counter++)

    SumSqr += Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);

    StdDev = Math.sqrt(SumSqr / Period);



    if(close() > close(-1)){

    u = StdDev;

    d = 0

    }

    else{

    d = StdDev;

    u = 0;

    }

    U = (13 * U_1 + u) / 14;

    D = (13 * D_1 + d) / 14;

    RVI = 100 * U / (U + D);

    if (getBarState() == BARSTATE_NEWBAR){

    U_1 = U;

    D_1 = D;

    }



    return RVI;

    }


    This RVI was subsequently refined by Donald Dorsey in an article in the TASC September 1995 issue.

    Instead of using the close in the calculation of the RVI Dorsey changed it’s calculation using the highs and the lows. The 1995 Tradestation code is given but since I do not know the TS easy language I am unable to use it for help in converting the new RVI into an efs.

    However I have tried modifying the original code from TS Support by using the high and low. The new RVI appears to be plotting on a chart but I am uncertain as to whether my modification has resulted in a correctly working new RVI. I am attaching my modified efs and would be grateful if someone could kindly check if the resultant RVI plot/logic is working correctly. The TS code is also attached.

    I have not tried coding the “inertia” section and any help in including it would be very much appreciated too.

    Robert
    Attached Files

  • #2
    Oops! The modified efs was not attached.

    Here it is
    Attached Files

    Comment


    • #3
      Re: Relative Volatility Index – Revised Computation Basis

      Robert
      Based on my understanding of the TradeStation code you posted those are three separate functions
      While it is possible to calculate them in a single function your code does not currently do that correctly and would require too many modifications so I would suggest that you start from scratch and calculate them as separate efs or functions as this will also make it easier for you to compute the Inertia indicator
      To calculate the Inertia indicator you need to compute the RVI of the High and of the Low separately and then average the sum of the resulting values divided by 2.
      The easiest way to do this is to modify the original TS Support script and make two versions of it each with its own logic one based on the High and the other on the Low calling them [for example] RVIofHigh and RVIofLow
      Then in a third efs you use two instances of the efsExternal() function to call the individual efs and use these values to calculate the indicator which as I explained earlier is the average of the sum of the two values divided by two. Given that average((a+b)/2) is the same as (average(a)+average(b))/2 you can simplify this part of the code by directly creating the averages of the values of the called efs ie
      PHP Code:
      var RVIH sma(20,efsExternal("/.../RVIofHigh,efs",Period));
      var 
      RVIL sma(20,efsExternal("/.../RVIofLow.efs",Period)); 
      and then calculating the sum of the values of the two variables divided by 2 which should return the value of the indicator
      When calculating the separate scripts of the RVI of the High and of the Low keep in mind that the original TS Support code has a logic error [which is also in your code] that will cause it to return incorrect results in real time.
      To correct this error you will need to declare the variables U and D as global variables rather than local. This is because they need to persist between iterations of the efs so that you can assign their values to the variables U_1 and D_1 at the beginning of each new bar
      You will then also need to move the section of code
      PHP Code:
      if (getBarState() == BARSTATE_NEWBAR){
          
      U_1 U;
          
      D_1 D;

      to the line above where U and D are calculated otherwise you will be transferring the values of U and D as they are calculated at the beginning of each bar instead of their last completed values
      On a side note you need to be aware that when you have more than one item to be executed based on the same condition these need to be enclosed in curly brackets eg
      PHP Code:
      if(myCondition){
          
      myVar1 //logic to calculate myVar1
          
      myVar2 //logic to calculate myVar2

      else only the first item will be executed by that conditional statement. In general I find it is good practice to always use curly brackets even if you are executing only one item ie
      PHP Code:
      if(myCondition){
          
      myVar //logic to calculate myVar

      Hope this helps
      Alex


      Originally posted by charttrader
      I found this code for the RVI [by Donald Dorsey] provided by TS Support on February 28, 2003:

      code:


      / **************************************************
      Description: This Indicator plots the Relative Volitility Index

      Provided By: TS Support, LLC for eSignal

      ************************************************** */



      function preMain(){

      setStudyTitle("Relative Volatility Index");

      setCursorLabelName("RVI",0);

      setDefaultBarFgColor(Color.red,0);

      addBand(30, PS_SOLID, 1, Color.grey);

      addBand(70, PS_SOLID, 1, Color.grey);

      }

      var U_1 = 0;

      var D_1 = 0;

      var ma = null;





      function main(Period){

      if(Period == null)

      Period = 10;

      var StdDev = 0, u = 0, d = 0, U = 0, D = 0, SumSqr = 0;

      if(ma == null)

      ma = new MAStudy(Period, 0, "Close", MAStudy.SIMPLE);



      for(counter = - Period + 1; counter <= 0; counter++)

      SumSqr += Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);

      StdDev = Math.sqrt(SumSqr / Period);



      if(close() > close(-1)){

      u = StdDev;

      d = 0

      }

      else{

      d = StdDev;

      u = 0;

      }

      U = (13 * U_1 + u) / 14;

      D = (13 * D_1 + d) / 14;

      RVI = 100 * U / (U + D);

      if (getBarState() == BARSTATE_NEWBAR){

      U_1 = U;

      D_1 = D;

      }



      return RVI;

      }


      This RVI was subsequently refined by Donald Dorsey in an article in the TASC September 1995 issue.

      Instead of using the close in the calculation of the RVI Dorsey changed it’s calculation using the highs and the lows. The 1995 Tradestation code is given but since I do not know the TS easy language I am unable to use it for help in converting the new RVI into an efs.

      However I have tried modifying the original code from TS Support by using the high and low. The new RVI appears to be plotting on a chart but I am uncertain as to whether my modification has resulted in a correctly working new RVI. I am attaching my modified efs and would be grateful if someone could kindly check if the resultant RVI plot/logic is working correctly. The TS code is also attached.

      I have not tried coding the “inertia” section and any help in including it would be very much appreciated too.

      Robert

      Comment


      • #4
        New RVI

        Hello Alex

        Thank you very much for your intructions on modifying the original RVI to the new version of the indicator.

        I have followed your instructions and the new efs appear to be plotting on a chart. With respect to the Inertia efs I am quite apprehensive of my use of the efsExternal() function as this is the first time that I am using it. 'Inertia is simply a 20 period simple moving average of the new RVI'

        I now have two efs - one for the RVI based on the highs and one based on the lows. Dorsey incorporates both the high and low so that only one indicator line is plotted in the indicator pane whereas I have one line each in two indicator panes. I have attached a graphic from the 1995 article showing this. I have attempted to do this myself in the attached efs 'NewRVI'. This is based on the article
        quote
        NewRVI = (RVIH + RVIL)/2
        unquote

        If you could spare some time to just check my modified efs[ all attached] and let me know that I have not missed anything out it would be very much appreciated. I will then clean up the efs where I have commented out the unneccessary lines.

        Once again thanking you very much for your help.
        Robert
        Attached Files
        Last edited by charttrader; 10-28-2008, 04:14 AM.

        Comment


        • #5
          I don't seem to be able to attach more than one efs to my post.

          Trying again
          Seems to be only able to make one attachment.

          The modified efs is as follows [seeing as I cannot attach another]:

          PHP Code:
          /***************************************************
          Description: This Indicator plots the Relative Volitility Index

          Provided By: TS Support, LLC for eSignal

          Modified for indicator to use the highs and the lows

          ***************************************************/

          var 0;
          var 
          0;

          function 
          preMain(){

              
          setStudyTitle("RVI-Inertia");

              
          setCursorLabelName("NewRVI",0);

              
          setDefaultBarFgColor(Color.red,0);

              
          addBand(40PS_SOLID1Color.red);

              
          addBand(50PS_SOLID2Color.green);

              
          addBand(60PS_SOLID1Color.blue);
              
              



          }

          var 
          U_1 0;

          var 
          D_1 0;

          var 
          ma null;





          function 
          main(Period){

          /*if(Period == null)

          Period = 10;

          var StdDev = 0, u = 0, d = 0, SumSqr = 0;

          if(ma == null)

          ma = new MAStudy(Period, 0, "Close", MAStudy.SIMPLE);



          for(counter = - Period + 1; counter <= 0; counter++)

          SumSqr += Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);

          StdDev = Math.sqrt(SumSqr / Period);



          if(close() > close(-1)){

          u = StdDev;

          d = 0

          }

          else{

          d = StdDev;

          u = 0;

          }
          if (getBarState() == BARSTATE_NEWBAR){

          U_1 = U;

          D_1 = D;

          }

          U = (13 * U_1 + u) / 14;

          D = (13 * D_1 + d) / 14;

          RVI = 100 * U / (U + D);*/

          var RVIH efsExternal("RVIofHigh.efs"10));
          var 
          RVIL efsExternal("RVIofLow.efs"10));

          NewRVI = (RVIH RVIL)/2

          return NewRVI;


          Attached Files
          Last edited by charttrader; 10-28-2008, 04:29 AM.

          Comment


          • #6
            Alex

            My apologies for these few messy posts. My apologies to eSignal forum too. I have very limited experience of postings in forums and I was trying to attach more than one efs which obviously isn't permitted.

            My modified RVI of the highs is appened as 'RVIofHigh':


            PHP Code:
            /***************************************************
            Description: This Indicator plots the Relative Volitility Index

            Provided By: TS Support, LLC for eSignal

            Modified using the high instead of the close

            ***************************************************/
            var 0
            var 
            0;


            function 
            preMain(){

                
            setStudyTitle("RVIofHigh");

                
            setCursorLabelName("RVIH",0);

                
            setDefaultBarFgColor(Color.red,0);

                
            addBand(40PS_SOLID1Color.red);

                
            addBand(50PS_SOLID2Color.green);

                
            addBand(60PS_SOLID1Color.blue);
                
                



            }

            var 
            U_1 0;

            var 
            D_1 0;

            var 
            ma null;





            function 
            main(Period){

            if(
            Period == null)

            Period 10;

            var 
            StdDev 000SumSqr 0;

            if(
            ma == null)

            ma = new MAStudy(Period0"High"MAStudy.SIMPLE);



            for(
            counter = - Period 1counter <= 0counter++)

            SumSqr += Math.pow((high(counter) - ma.getValue(MAStudy.MA)),2);

            StdDev Math.sqrt(SumSqr Period);



            if(
            high() > high(-1)){

            StdDev;

            0

            }

            else{

            StdDev;

            0;

            }
            if (
            getBarState() == BARSTATE_NEWBAR){

            U_1 U;

            D_1 D;

            }

            = (13 U_1 u) / 14;

            = (13 D_1 d) / 14;

            RVIH 100 / (D);





            return 
            RVIH;


            Could you please look at it to see if I have followed your instructions correctly. The RVIofLow is the same except for the changes to use the low.

            Thanks again.
            Robert
            Last edited by charttrader; 10-28-2008, 04:49 AM.

            Comment


            • #7
              Robert
              You are welcome
              As far as I can see the studies appear to be correct
              Alex

              Comment


              • #8
                Robert,

                I recoded your separate scripts into one where you can select whether you want to plot, the RVIH, RVIL, NEWRVI, or all three.

                I was just testing the indicator and since I already coded it, maybe it will be useful to you.
                Attached Files

                Comment


                • #9
                  Alex and Wayne

                  Thank you both very much for your help. Much appreciated.

                  Thank you Wayne for re-coding everything into one script.

                  Best wishes and regards

                  Robert

                  Comment

                  Working...
                  X